import {
  getListCode
} from "@/api/business/definition";
export const Mixins = {
  data() {
    return {
      codeList: [
        "FILES-YEAR", // 档案年份
        "FILES-SCREEN-TIME", // 筛查时间
        "FILES-CAREER", // 职业
        "FILES-MARITALSTATUS", // 婚姻状况
        "FILES-EDUC", // 受教育程度
        "FILES-sibling", // 兄弟姐妹
        "FILES-CHILD", // 子女
        "FILES-INCOME", // 本人年均收入
        "FILES-RESIDENCY", // 居住情况
        "FILES-CELLPHONE", // 手机
        "FILES-LANDLINE", // 固定电话
        "FILES-EMAIL", // 邮箱
        "FILES-AD", // 居住城市行政区划
        "FILES-ADDRESS", // 居住详细地址
        "FILES-ZIP", // 居住地址邮编
        "FILES-CONTAXTNAME", // 联系人姓名
        "FILES-CONTACTMOBILE", // 联系人电话
        "FILES-CONTACTRELATION", // 与联系人关系
        "ZL-JBXX-YLFF", // 主要医疗付费方式
      ],
      recordDtoList: [],
    };
  },
  methods: {
    async getRecordDtoList() {
      for (let i = 0; i < this.codeList.length; i++) {
        const code = this.codeList[i];
        const queryParams = {
          pageNum: 1,
          pageSize: 1,
          param: {
            code,
          },
        };
        await getListCode(queryParams).then((res) => {
          if (res.data.total) {
            const recordData = {
              ...res.data.list[0]
            };
            const data = {
              answer: undefined,
              code,
              codeName: recordData.name,
              operatorName: recordData.operatorName,
              required: recordData.required,
              options: recordData.options
            };
            this.recordDtoList.push(data);
          }
        });
      }
      this.getRules();
    },
    getRules() {
      const rules = {};
      for (let i = 0; i < this.recordDtoList.length; i++) {
        const item = this.recordDtoList[i];
        if (!item.required) {
          rules[`${item.code}`] = [{
            required: true,
            message: `${item.name}不能为空`,
            trigger: "blur",
          }, ];
        }
      }
      this.rules = {
        ...this.rules,
        ...rules
      };
    },
  },
};
